﻿using System.Windows.Data;

namespace DeepEarth.Map.BingMaps
{
    public class BingLocationConverter : IValueConverter
    {
        public static BingLocationConverter Instance = new BingLocationConverter();

        public static Microsoft.Maps.MapControl.Location ConvertToBing(DeepEarth.Core.Location deepEarthLocation)
        {
            return new Microsoft.Maps.MapControl.Location
            {
                Longitude = deepEarthLocation.Longitude,
                Latitude = deepEarthLocation.Latitude,
                Altitude = deepEarthLocation.Altitude
            };
        }

        public static DeepEarth.Core.Location ConvertToDeepEarth(Microsoft.Maps.MapControl.Location bingLocation)
        {
            return new DeepEarth.Core.Location
            {
                Longitude = bingLocation.Longitude,
                Latitude = bingLocation.Latitude,
                Altitude = bingLocation.Altitude
            };
        }

        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ConvertToBing(value as DeepEarth.Core.Location);
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ConvertToDeepEarth(value as Microsoft.Maps.MapControl.Location);
        }
    }
}
